//
//  BaseController.m
//  OCProject
//
//  Created by 王明钦 on 2018/2/9.
//  Copyright © 2018年 oc. All rights reserved.
//

#import "BaseController.h"

@interface BaseController ()

@property (nonatomic, strong) UIButton *backBtn;

@property (nonatomic, strong) UILabel *titleTv;

@property (nonatomic, strong) UIButton *rightBtn;

@end

@implementation BaseController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //默认背景颜色
    self.view.backgroundColor = BACKGROUD_COLOR;

    if ([self isNeedHeader]) {
        [self addHeader];
    }
    
}

-(void)addHeader{
    UIView *header = [[UIView alloc] init];
    header.backgroundColor = NAV_BAR_COLOR;
    [self.view addSubview:header];
    [header mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 64));
    }];

    self.backBtn = [[UIButton alloc] init];
    [self.backBtn setImage:[UIImage imageNamed:@"arrow-left"] forState:UIControlStateNormal];
    [self.backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.backBtn];
    [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.top.equalTo(header.mas_top).offset(24);
        make.bottom.equalTo(header.mas_bottom).offset(0);
        make.centerY.equalTo(header);
    }];
    
    self.titleTv = [[UILabel alloc] init];
    self.titleTv.textColor = TITLE_COLOR;
    self.titleTv.numberOfLines = 1;
    [self.view addSubview:self.titleTv];
    [self.titleTv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(header.mas_top).offset(24);
        make.bottom.equalTo(header.mas_bottom).offset(0);
        make.centerX.equalTo(header);
     
    }];
    
    self.rightBtn = [[UIButton alloc] init];
    self.rightBtn.titleLabel.font = FONT_24PX;
    [self.rightBtn addTarget:self action:@selector(rightAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.rightBtn];
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(header.mas_top).offset(24);
        make.bottom.equalTo(header.mas_bottom).offset(0);
        make.centerY.equalTo(header);
        make.right.equalTo(header).offset(-10);
    }];
    
}

-(BOOL)isNeedHeader{
    return true;
}

-(void)rightAction{
    NSLog(@"父类");
 
}

-(void)setMainTitle:(NSString *)title{
    if (!EMPTY(title) && self.backBtn != nil) {
        self.titleTv.text = title;
    }
    
}

-(void)setSubTitle:(NSString *)subTitle{
    if (!EMPTY(subTitle) && self.rightBtn != nil) {
        [self.rightBtn setTitle:subTitle forState:UIControlStateNormal];
    }
    
}

-(void)backAction{
    [self.navigationController  popViewControllerAnimated:YES];
    
}

-(void)showLoading:(NSString *)status{
    [SVProgressHUD dismiss];
    [SVProgressHUD showWithStatus:status];
}

-(void)showError:(NSString *)error{
    [SVProgressHUD dismiss];
    [SVProgressHUD showErrorWithStatus:error];
}

-(void)showSuccess:(NSString *)status{
    [SVProgressHUD dismiss];
    [SVProgressHUD showSuccessWithStatus:status];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
